package com.xr.zk.zul.tree.model;

import org.zkoss.zul.AbstractTreeModel;

import com.xr.zk.zul.tree.node.TreeNode;

public class BaseTreeModel extends AbstractTreeModel<TreeNode> {
	private static final long serialVersionUID = 1L;
	
	public BaseTreeModel(TreeNode root) {
		super(root);
	}

	public TreeNode getChild(TreeNode parent, int index) {
		if (null == parent.getChildren()) {
			return null;
		}
		return parent.getChildren().get(index);
	}

	public int getChildCount(TreeNode parent) {
		if (null == parent.getChildren()) {
			return 0;
		}
		return parent.getChildren().size();
	}

	public boolean isLeaf(TreeNode node) {
		if (null == node.getChildren()) {
			return true;
		}
		return node.getChildren().size() == 0;
	}
}
